package com.neu.admin;

import com.neu.common.validator.Order;
import com.neu.common.validator.Sort;
import com.neu.domain.ShoppingFootprint;
import com.neu.service.ShoppingFootprintService;
import com.neu.util.response.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 历史足迹
 * 王宸宇
 */
@RestController
@RequestMapping("/admin/footprint")
public class AdminFootprintController {
    @Autowired
    private ShoppingFootprintService shoppingFootprintService;
    @GetMapping("/list")
    public ResponseEntity<BaseResponse<ShoppingFootprint>> list(Integer userId, Integer goodsId,
                                                              @RequestParam(defaultValue = "10") String pageSize,

                                                              @RequestParam(defaultValue = "1") String pageNum,

                                                              @Sort @RequestParam(defaultValue = "addTime") String sort,

                                                              @Order @RequestParam(defaultValue = "desc") String order) {

        try {
            List<ShoppingFootprint> footprintList = shoppingFootprintService.querySelective(pageSize, pageNum, userId, goodsId, sort, order);
            if (footprintList != null) {
                return BaseResponse.generateOKListResponseEntity(footprintList);
            }
            return BaseResponse.generateBadResponseEntity(500, "查询信息不存在", "");
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.generateBadResponseEntity(500, "系统异常", "");
        }
    }
    }
